package com.zxl.permission.controller;

import com.alibaba.fastjson.JSONObject;
import com.zxl.permission.entity.User;

import com.zxl.permission.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public String userList() {
        JSONObject res =  userService.list();
        return res.toJSONString();
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public String add(@RequestBody User user) {
        JSONObject res =  userService.add(user);
        return res.toJSONString();
    }

    @RequestMapping(value = "/alter",method = RequestMethod.POST)
    @ResponseBody
    public String alter(@RequestBody User user) {
        JSONObject res =  userService.alter(user);
        return res.toJSONString();
    }

    @RequestMapping(value = "/remove",method = RequestMethod.POST)
    @ResponseBody
    public String remove(@RequestBody Map<String, Object> body) {
        String username=(String)body.get("username");
        JSONObject res =  userService.remove(username);
        return res.toJSONString();
    }

}
